//
//  MyPointsCell.swift
//  Eternity
//
//  Created by cll12_12 on 2016/12/19.
//  Copyright © 2016年 ZhengWei. All rights reserved.
//

import UIKit

class MyPointsCell: UITableViewCell {

    // MARK: - life cycle
    override init(style: UITableViewCellStyle, reuseIdentifier: String?) {
        super.init(style: style, reuseIdentifier: reuseIdentifier)
        
        initBaseLayout()
        layoutPageSubviews()
        self.selectionStyle = .none
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    // MARK: - private method
    func initBaseLayout() {
        self.addSubview(dateLabel)
        self.addSubview(sourceLabel)
        self.addSubview(typeLabel)
        self.addSubview(pointsLabel)
        self.addSubview(lineView)
    }
    
    func layoutPageSubviews() {
        dateLabel.snp.makeConstraints { (make) in
            make.left.equalTo(self).offset(14)
            make.centerY.equalTo(self)
            make.width.equalTo((SCREEN_WIDTH-80+50)/4)
            make.height.equalTo(12)
        }
        
        sourceLabel.snp.makeConstraints { (make) in
            make.left.equalTo(dateLabel.snp.right).offset(20)
            make.centerY.equalTo(self)
            make.width.equalTo((SCREEN_WIDTH-80)/4)
            make.height.equalTo(14)
        }
        
        typeLabel.snp.makeConstraints { (make) in
            make.left.equalTo(sourceLabel.snp.right).offset(20)
            make.centerY.equalTo(self)
            make.width.equalTo((SCREEN_WIDTH-80)/4)
            make.height.equalTo(14)
        }
        
        pointsLabel.snp.makeConstraints { (make) in
            make.right.equalTo(self).offset(-22)
            make.centerY.equalTo(self)
            make.width.equalTo((SCREEN_WIDTH-80-50)/4)
            make.height.equalTo(14)
        }
    }
    
    func configUI() {
        dateLabel.text = "2016-12-19"
        sourceLabel.text = "HARMAY"
        typeLabel.text = "积分收入"
        pointsLabel.text = "+100"
    }
    
    // MARK: - setters and getters
    var _index: Int?
    var index: Int? {
        set {
            if newValue == 0 {
                self.backgroundColor = UIColor(hexString: "#FBFBFB")
                pointsLabel.font = UIFont(name: "PingFangSC-Regular", size: 14)
                dateLabel.textColor = UIColor(hexString: "#252525")
                sourceLabel.textColor = UIColor(hexString: "#252525")
                typeLabel.textColor = UIColor(hexString: "#252525")
                pointsLabel.textColor = UIColor(hexString: "#252525")
                                
                dateLabel.text = "时间"
                sourceLabel.text = "来源"
                typeLabel.text = "类型"
                pointsLabel.text = "积分"
                
                lineView.frame = CGRect(x: 0, y: 35, width: SCREEN_WIDTH, height: 1)
            }
        } get {
            return _index
        }
    }
    
    var _lineView: UIView!
    var lineView: UIView {
        if _lineView == nil {
            _lineView = UIView(frame: CGRect(x: 14, y: 47, width: SCREEN_WIDTH-14, height: 1))
            _lineView.backgroundColor = UIColor(hexString: "#DDDDDD")
        }
        return _lineView
    }
    
    var _dateLabel: UILabel!
    var dateLabel: UILabel {
        if _dateLabel == nil {
            _dateLabel = UILabel()
            _dateLabel.font = UIFont(name: "PingFangSC-Regular", size: 13)
            _dateLabel.textColor = UIColor(hexString: "#666666")
            _dateLabel.textAlignment = .center
        }
        return _dateLabel
    }
    
    var _sourceLabel: UILabel!
    var sourceLabel: UILabel {
        if _sourceLabel == nil {
            _sourceLabel = UILabel()
            _sourceLabel.font = UIFont(name: "PingFangSC-Regular", size: 13)
            _sourceLabel.textColor = UIColor(hexString: "#666666")
            _sourceLabel.textAlignment = .center
        }
        return _sourceLabel
    }
    
    var _typeLabel: UILabel!
    var typeLabel: UILabel {
        if _typeLabel == nil {
            _typeLabel = UILabel()
            _typeLabel.font = UIFont(name: "PingFangSC-Regular", size: 13)
            _typeLabel.textColor = UIColor(hexString: "#666666")
            _typeLabel.textAlignment = .center
        }
        return _typeLabel
    }
    
    var _pointsLabel: UILabel!
    var pointsLabel: UILabel {
        if _pointsLabel == nil {
            _pointsLabel = UILabel()
            _pointsLabel.font = UIFont(name: "HelveticaNeue", size: 13)
            _pointsLabel.textColor = UIColor(hexString: "#252525")
            _pointsLabel.textAlignment = .right
        }
        return _pointsLabel
    }
    
    

}
